<?php
namespace app\common\service;

use app\common\model\PostClass as PostClassModel;


class PostClass{

    public function paginate($pageSize=20){

        $postClassModel = new PostClassModel();
        $postClass = $postClassModel -> order('id desc')->paginate($pageSize);
        return $postClass;
    }

    public function find($id){

        return PostClassModel::get($id);
    }

    public function insert($data){
        $postClassModel = new PostClassModel();
        $result = $postClassModel->validate("PostClassValidate.add")->save($data);

        if(false === $result){
            return ['state'=>0,'message'=>$postClassModel->getError()];
        }

        return ['state'=>1,'message'=>'','insertId'=>$postClassModel->id];
    }

    public function update($data){

        $postClassModel = new PostClassModel();

        if(intval($data['id']) <1){
            return ['state'=>0,'message'=>"参数错误"];
        }

        $result = $postClassModel->validate('PostClassValidate.edit')->save($data,['id'=>intval($data['id'])]);

        if(false === $result){
            return ['state'=>0,'message'=>$postClassModel->getError()];
        }

        return ['state'=>1,'message'=>''];
    }

    public function delete($ids){
        $postClassModel = new PostClassModel();

        $count = $postClassModel ->destroy($ids);

        return $count;
    }

}